#include <stdio.h>
#include <malloc.h>

#include "queue.h"

int main()
{


    /* 分配队列指针内存 */
    QUEUE *pstQueue = (QUEUE *)malloc(sizeof(QUEUE));

    /* 初始化队列结构体 */
    if (initQueue(pstQueue) == true)
    {
        printf("Queue init ok!\n");
    }

    char acStrFirst[] = "1st in the queue";
    char acStrSecond[] = "2nd in the queue";
    char acStrLast[] = "last in the queue";

    /* 测试队列加入操作 */
    if (enQueue(pstQueue, acStrFirst, sizeof(acStrFirst)) == true)
    {
        printf("first enQueue ok!\n");
    }
    if (enQueue(pstQueue, acStrSecond, sizeof(acStrSecond)) == true)
    {
        printf("second enQueue ok!\n");
    }
    if (enQueue(pstQueue, acStrLast, sizeof(acStrLast)) == true)
    {
        printf("last enQueue ok!\n");
    }

    /* 测试队列读取操作 */
    int i;
    for (i = 0; i < 2; i++)
    {
        NODE *pstNode = (NODE *)malloc(sizeof(NODE));
        if ((deQueue(pstQueue, pstNode)) == true)
        {
            printf("%d:%s :%d\n", i, (char *)pstNode->pcData, pstNode->iDataLen);
        }
        free(pstNode->pcData);
        free(pstNode);
    }
    /* 释放队列所占用的内存 */
    freeQueue(pstQueue);

    /* 释放内存 */
    if (pstQueue != NULL)
        free(pstQueue);

    return 0;
}
